home *** CD-ROM | disk | FTP | other *** search
- Path: matisse.eecs.uic.edu!dhanley
- From: dhanley@matisse.eecs.uic.edu (David Hanley)
- Newsgroups: comp.lang.misc,comp.lang.perl.misc,comp.lang.tcl,comp.lang.c,comp.lang.java
- Subject: Re: Relative Speed of Perl vs. Tcl vs. C
- Followup-To: comp.lang.misc,comp.lang.perl.misc,comp.lang.tcl,comp.lang.c,comp.lang.java
- Date: 22 Jan 1996 22:35:44 GMT
- Organization: University of Illinois at Chicago
- Message-ID: <4e13g0$3ip6@tigger.cc.uic.edu>
- References: <4dhuoj$cbe@shellx.best.com> <9602122.8425@mulga.cs.mu.OZ.AU> <ukvim4pceu.fsf@linda.teleport.com>
- NNTP-Posting-Host: matisse.eecs.uic.edu
- X-Newsreader: TIN [version 1.2 PL2]
-
- Randal L. Schwartz (merlyn@stonehenge.com) wrote:
- : >>>>> "Tim" == Tim Hollebeek <tim@franck> writes:
-
- : Tim> An important point, though, is that all 'reasonably' written C programs
- : Tim> will run within a factor of 2 or so of 'about as fast as you can get,
- : Tim> while for some problems, Perl won't be able to break through about a
- : Tim> factor of 7 or so, even if you are a Perl expert.
-
- : I just want to point out to everyone that you are simply making that
- : figure up based on what you think Perl is doing internally.
-
- : Tom Christiansen has had a long-standing bet that someone can't give
- : him a program in C that he can't make run no more than "e" times
- : slower (about 2.8 for you non-math-geeks) in Perl. So far, no one's
- : done it.
-
- I find that exceptionally hard to beleive. What is this bet
- exactly? Do I get any money for "winning" it? For example, I have
- some programs that are heavily math-intensive, ( matrix multiplies,
- number cracking, image manipulation ) which I have written in C,
- which I would be shocked as all get-out to see run nearly as fast in
- PERL.
-
- : That's also been my experience as well. Perl is *not* slow. In fact,
- : a Perl-written egrep is *faster* than most vendor's egrep, for
- : example.
-
- Sure, as long as you are writing grep, it's great. That's
- because you're then spending 99% of your time in some C code that's
- already been way optimized.
-
- : So, if you have a number of "7-times-slower" programs, post'em, and I
- : bet we can easily boost their speed by two or three times.
-
- Okay. It's a bit long, but this finds amicable number pairs
- using the dumb old-try-every-number method. I'd be shocked to see a
- 2.8 factor, and be even mildly surprised to even see 7 times as fast
- C->Perl.
-
- #include <iostream.h>
- #include <math.h>
- #include <stdlib.h>
- #include <string.h>
-
- typedef unsigned int Int;
- char *Table;
-
- unsigned int SumOfFactors( Int Num )
- {
- Int Res = 1;
- Int SNum = Int( floor( sqrt( (double) Num ) ) );
- memset( Table , 0 , SNum );
- for( Int i = 2 ; i < SNum ; ++ i )
- {
- if ( Table[ i ] == 0 )
- {
- int divresult = Num / i;
- int Remainder = Num - ( divresult * i ) ;
- if ( Remainder == 0 )
- {
- Res += i;
- Res += divresult;
- }
- else
- {
- int temp = i;
- while( temp < SNum )
- {
- Table[ temp ] = 1;
- temp += i;
- }
- }
- }
- }
- return Res;
- }
-
- main( int argc , char *argv[] )
- {
- Table = new char[ 1000000 ];
-
- for( Int i = 1 ; i < 1000000000 ; ++i )
- {
- if ( ( i % 100000 ) == 0 )
- {
- cout << "Reached " << i << endl;
- }
- Int r1 = SumOfFactors( i );
- if ( r1 == i )
- cout << "Perfect " << i << endl;
- else
- {
- Int r2 = SumOfFactors( r1 );
- if ( r2 == i )
- cout << "Amicable : " << r1 << " " << r2 << endl;
- }
- }
- }
-
-
-
- --
- ------------------------------------------------------------------------------
- David Hanley, |______ Computer Science graduate student.
- dhanley@lac.ecs.uic.edu |\ ___/__ Martial Artist. Biker. Chess Freak
- www_lac.eecs.uic.edu/~dhanley/| \\ / / Libertarian. Atheist. Bisexual.
- My employer barely KNOWS me. | \/BI/ Aspiring novelist.Joyce Kafka Neitzchie
- -----------------------------------\/-----------------------------------------
- Member:Hermetic order of the Golden Dawn.
-